import React, { Suspense } from "react";
import { Spin } from "antd";

const withLazyComponent = <P extends object>(
  WrappedComponent: React.ComponentType<P>
) => {
  return class extends React.PureComponent<P & any> {
    static displayName = WrappedComponent.displayName;

    render() {
      return (
        <Suspense fallback={<Spin spinning={true} className="global-spin" />}>
          <WrappedComponent {...(this.props as P)} {...this.state} />
        </Suspense>
      );
    }
  };
};
export default withLazyComponent;
